<template>
	<view>
		<view class=" margin-bottom">
			<swiper class="screen-swiper" style="height: 260rpx;" :circular="true" :autoplay="true" interval="2500"
				duration="800">
				<swiper-item v-for="(item,index) in swiperList" :key="index" @tap="goPage(item.url)">
					<image :src="item.imageUrl" mode="heightFix"></image>
				</swiper-item>
			</swiper>
		</view>


		<view class="margin-lr">

			<view v-for="(item,index) in orderlist" :key="index"
				class="flex align-center bg margin-top-sm padding radius" @click="goOrder(item.url)">
				<image :src="item.imageUrl?item.imageUrl:'../../static/images/index/yikoujia.png'" style="width: 88upx;height: 88upx;"></image>
				<view class="margin-left-sm" style="width: 90%;">
					<view class="text-lg text-bold">{{item.name}}</view>
					<view class="text-sm" style="color: #666666;">{{item.describes}}</view>
				</view>
			</view>
			<!-- <view class="flex align-center bg margin-top-sm padding radius" @click="goOrder(1)">
				<image src="../../static/images/index/yikoujia.png" style="width: 88upx;height: 88upx;"></image>
				<view class="margin-left-sm" style="width: 90%;">
					<view class="text-lg text-bold">一口价下单</view>
					<view class="text-sm" style="color: #666666;">全国统一标准价，支付后，师傅立即接单 与客户预约上门服务</view>
				</view>
			</view>
			<view class="flex align-center bg margin-top-sm padding radius" @click="goOrder(2)">
				<image src="../../static/images/index/baojia.png" style="width: 88upx;height: 88upx;"></image>
				<view class="margin-left-sm" style="width: 90%;">
					<view class="text-lg text-bold">报价下单</view>
					<view class="text-sm" style="color: #666666;">全国统一标准价，支付后，师傅立即接单 与客户预约上门服务</view>
				</view>
			</view>
			<view class="flex align-center bg margin-top-sm padding radius" @click="goOrder(3)">
				<image src="../../static/images/index/xuanshang.png" style="width: 88upx;height: 88upx;"></image>
				<view class="margin-left-sm" style="width: 90%;">
					<view class="text-lg text-bold">悬赏下单</view>
					<view class="text-sm" style="color: #666666;">全国统一标准价，支付后，师傅立即接单 与客户预约上门服务</view>
				</view>
			</view> -->
		</view>


		<view class="text-center margin-top-xl">已有<text
				style="color: #557EFD;font-size: 48upx;">{{orderCount}}</text>个订单成功找到师傅</view>

		<u-tabbar :list="tabbarList" :mid-button="true" bg-color="#FFFFFF" active-color="#557EFD"
			inactive-color="#999999">
		</u-tabbar>
	</view>
</template>

<script>
	export default {
		data() {
			return {
				swiperList: [],
				orderCount: 0,
				arr:[],
				orderlist: [],

				tabbarList: this.$store.state.list,
			}
		},
		onLoad() {
			this.getBannerList()
			this.getList()
			var that = this;
			that.$Request.getT('/app/common/type/249').then( async res => { //私聊消息通知
				if (res.code == 0) {
					if (res.data && res.data.value) {
						await that.arr.push(res.data.value)
					}
				}
			})
			that.$Request.getT('/app/common/type/236').then( async res => { //退款通知
				if (res.code == 0) {
					if (res.data && res.data.value) {
						await that.arr.push(res.data.value)
					}
				}
			})
			
			that.$Request.getT('/app/common/type/312').then( async res => { //订单状态通知
				if (res.code == 0) {
					if (res.data && res.data.value) {
						await that.arr.push(res.data.value)
					}
				}
			})
		},
		onShow() {
			this.current = 2
			this.getorderNum()
		},
		methods: {
			//获取轮播图
			getList() {
				this.$Request.get("/app/banner/selectBannerList", {
					classify: 10
				}).then(res => {
					if (res.code == 0) {
						this.orderlist = res.data
					}
				});
			},
			getorderNum() {
				this.$Request.get("/app/help/selectHelpOrderCount").then(res => {
					if (res.code == 0) {
						this.orderCount = res.data
					}
				});
			},
			goOrder(url) {
				var that = this;
				wx.requestSubscribeMessage({
					tmplIds: that.arr,
					success(re) {
						console.log(JSON.stringify(re),
							'++++++++++++++')
						var datas = JSON.stringify(re);
						if (datas.indexOf("accept") != -1) {
							console.log(re)
							uni.setStorageSync('sendMsg', true)
						}
					},
					fail: (res) => {
						console.log(res)
					}
				})
				let userId = uni.getStorageSync('userId')
				if (userId) {
					uni.navigateTo({
						url
					})
					// uni.navigateTo({
					// 	url: '/package/pages/classification/index?renwu=' + index
					// })
				} else {
					uni.showModal({
						title: '提示',
						content: '您还未登录,请先登录',
						success: function(res) {
							if (res.confirm) {
								console.log('用户点击确定');
								uni.navigateTo({
									url: '/pages/public/login'
								})
							} else if (res.cancel) {
								console.log('用户点击取消');
							}
						}
					})
				}
			},
			goPage(url) {
				let userId = uni.getStorageSync('userId')
				if (userId) {
					if (url.indexOf('/pages/') !== -1) {
						uni.navigateTo({
							url
						});
					} else {
						//#ifndef H5
						uni.navigateTo({
							url: '/pages/index/webView?url=' + url
						});
						//#endif
						//#ifdef H5
						window.location.href = url;
						//#endif	
					}
				} else {
					uni.showModal({
						title: '提示',
						content: '您还未登录,请先登录',
						success: function(res) {
							if (res.confirm) {
								console.log('用户点击确定');
								uni.navigateTo({
									url: '/pages/public/login'
								})
							} else if (res.cancel) {
								console.log('用户点击取消');
							}
						}
					})
				}

			},
			//获取轮播图
			getBannerList() {
				this.$Request.get("/app/banner/selectBannerList", {
					classify: 7
				}).then(res => {
					if (res.code == 0) {
						this.swiperList = res.data
					}
				});
			},
		}
	}
</script>

<style>
	page {
		background: #F7F7F7;
	}

	.bg {
		background: #ffffff;
	}
</style>